﻿/* 
 * ServersDesign.cs
 * 
 * Author - Ankit Gupta and Gaurav Aggarwal
 * 
 * This file handles component design of Servers tab.
 * 
 */

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using Microsoft.Win32;
using System.Windows.Forms;
using System.Text;

partial class ServersControl
{
    public Label fileLabel = new Label();
    public Label volumeLabel = new Label();
    public Label serverLabel = new Label();
    public Label rankLabel = new Label();
    public Label fileServerLabel = new Label();
    public Label volumeServerLabel = new Label();
    public TextBox serverTextBox = new TextBox();
    public TextBox rankTextBox = new TextBox();
    public CheckBox fileCheckBox = new CheckBox();
    public CheckBox volumeCheckBox = new CheckBox();
    public RadioButton fileRadioButton = new RadioButton();
    public RadioButton volumeRadioButton = new RadioButton();
    public Button buttonAddUpdate = new Button();
    public Button buttonRemove = new Button();
    public Button applyButton = new Button();
    public Button cancelButton = new Button();
    public DataGridView datagrid = new DataGridView();
    public DataGridViewTextBoxColumn Column1 = new DataGridViewTextBoxColumn();
    public DataGridViewTextBoxColumn Column2 = new DataGridViewTextBoxColumn();
    public DataGridViewTextBoxColumn Column3 = new DataGridViewTextBoxColumn();

    public RegistryKey fileServers = Registry.LocalMachine.OpenSubKey("SOFTWARE\\OpenAFS\\Client\\Server Preferences\\File", true);
    public RegistryKey volumeServers = Registry.LocalMachine.OpenSubKey("SOFTWARE\\OpenAFS\\Client\\Server Preferences\\VLDB", true);
    public Array fileServer;
    public Array volumeServer;
    public int fileCount;
    public int volumeCount;

    public ServersControl()
    {

        if (fileServers != null)
        {
            fileServer = fileServers.GetValueNames();
            fileCount = fileServers.ValueCount;
        }

        if (volumeServers != null)
        {
            volumeServer = volumeServers.GetValueNames();
            volumeCount = volumeServers.ValueCount;
        }

        datagrid.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
        datagrid.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { Column1, Column2, Column3 });

        int i;
        for (i = 0; i < fileCount; i++)
            datagrid.Rows.Add(fileServer.GetValue(i).ToString(), "File Server", fileServers.GetValue(fileServer.GetValue(i).ToString()));
        for (i = 0; i < volumeCount; i++)
            datagrid.Rows.Add(volumeServer.GetValue(i).ToString(), "Volume Server", volumeServers.GetValue(volumeServer.GetValue(i).ToString()));

        datagrid.Location = new System.Drawing.Point(20, 12);
        datagrid.RowHeadersVisible = false;
        datagrid.BackgroundColor = Color.White;
        datagrid.ReadOnly = true;
        datagrid.Name = "datagrid";
        datagrid.Size = new System.Drawing.Size(330, 400);

        Column1.HeaderText = "Server";
        Column1.Name = "Column1";
        Column1.Width = 107;

        Column2.HeaderText = "Type";
        Column2.Name = "Column2";
        Column2.Width = 110;

        Column3.HeaderText = "Rank";
        Column3.Name = "Column3";
        Column3.Width = 110;

        // File or Volume Servers
        fileCheckBox.Location = new System.Drawing.Point(370, 12);
        fileCheckBox.Name = "fileCheckBox";
        fileCheckBox.Size = new System.Drawing.Size(20, 20);
        fileCheckBox.Checked = true;
        fileCheckBox.Click += new System.EventHandler(show_Click);

        fileLabel.Location = new System.Drawing.Point(390, 15);
        fileLabel.Name = "fileLabel";
        fileLabel.Size = new System.Drawing.Size(100, 15);
        fileLabel.Text = "Show File Servers";

        volumeCheckBox.Location = new System.Drawing.Point(370, 42);
        volumeCheckBox.Name = "volumeCheckBox";
        volumeCheckBox.Size = new System.Drawing.Size(20, 20);
        volumeCheckBox.Checked = true;
        volumeCheckBox.Click += new System.EventHandler(show_Click);

        volumeLabel.Location = new System.Drawing.Point(390, 45);
        volumeLabel.Name = "volumeLabel";
        volumeLabel.Size = new System.Drawing.Size(200, 15);
        volumeLabel.Text = "Show Volume Servers";

        // Server
        serverLabel.Location = new System.Drawing.Point(370, 250);
        serverLabel.Name = "serverLabel";
        serverLabel.Size = new System.Drawing.Size(40, 15);
        serverLabel.Text = "Server";

        serverTextBox.Location = new System.Drawing.Point(410, 247);
        serverTextBox.Name = "serverTextBox";
        serverTextBox.Size = new System.Drawing.Size(150, 30);

        // Rank
        rankLabel.Location = new System.Drawing.Point(370, 290);
        rankLabel.Name = "rankLabel";
        rankLabel.Size = new System.Drawing.Size(40, 15);
        rankLabel.Text = "Rank";

        rankTextBox.Location = new System.Drawing.Point(410, 287);
        rankTextBox.Name = "rankTextBox";
        rankTextBox.Size = new System.Drawing.Size(150, 30);

        // File Server
        fileRadioButton.Location = new System.Drawing.Point(410, 317);
        fileRadioButton.Name = "fileRadioButton";
        fileRadioButton.Size = new System.Drawing.Size(20, 20);
        fileRadioButton.Checked = true;

        fileServerLabel.Location = new System.Drawing.Point(430, 320);
        fileServerLabel.Name = "fileLabel";
        fileServerLabel.Size = new System.Drawing.Size(200, 15);
        fileServerLabel.Text = "File Server";

        // Volume Server
        volumeRadioButton.Location = new System.Drawing.Point(410, 347);
        volumeRadioButton.Name = "volumeRadioButton";
        volumeRadioButton.Size = new System.Drawing.Size(20, 20);

        volumeServerLabel.Location = new System.Drawing.Point(430, 350);
        volumeServerLabel.Name = "volumeLabel";
        volumeServerLabel.Size = new System.Drawing.Size(200, 15);
        volumeServerLabel.Text = "Volume Server";

        // Add/Update Button
        buttonAddUpdate.Location = new System.Drawing.Point(370, 380);
        buttonAddUpdate.Name = "buttonAddUpdate";
        buttonAddUpdate.Size = new System.Drawing.Size(90, 23);
        buttonAddUpdate.Text = "Add/Update";
        buttonAddUpdate.Click += new System.EventHandler(buttonAddUpdate_Click);

        // Remove Button
        buttonRemove.Location = new System.Drawing.Point(470, 380);
        buttonRemove.Name = "buttonRemove";
        buttonRemove.Size = new System.Drawing.Size(90, 23);
        buttonRemove.Text = "Remove";
        buttonRemove.Click += new System.EventHandler(buttonRemove_Click);

        // Apply Button
        applyButton.Location = new System.Drawing.Point(20, 460);
        applyButton.Name = "applyButton";
        applyButton.Size = new System.Drawing.Size(100, 23);
        applyButton.Text = "Apply";
        applyButton.Click += new System.EventHandler(applyButton_Click);

        // Cancel Button
        cancelButton.Location = new System.Drawing.Point(140, 460);
        cancelButton.Name = "cancelButton";
        cancelButton.Size = new System.Drawing.Size(100, 23);
        cancelButton.Text = "Cancel";
        cancelButton.Click += new System.EventHandler(cancelButton_Click);
    }
}